package com.qf.mvc02.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/cap")
public class KapcharController {

    @RequestMapping("/login")
    public Map<String,String> login(String usernam, String password, String cap, HttpSession session){

        // 先校验验证码是否正确
        final String captcha = (String) session.getAttribute("captcha");

        System.out.println(captcha);

        if (!captcha.equals(cap)){
            final HashMap<String, String> map = new HashMap<>();
            map.put("code","-1");
            map.put("msg","验证码错误");
            return map;
        }

        // 如果验证码正确再去查数据库，否则直接返回错误
        final HashMap<String, String> map = new HashMap<>();
        map.put("code","1");
        map.put("msg","登录成功");
        return map;
    }

}
